this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,t,i,n){"use strict";let s=e=>e,a,l;class r extends t.Text{constructor(e){super(e);this.matchers={catalogElement:new RegExp("^(product:)?#catalogElement([0-9]+)"),catalogSection:new RegExp("^(product:)?#catalogSection([0-9]+)"),catalog:new RegExp("^#Section([0-9]+)"),element:new RegExp("^#Element([0-9]+)"),block:new RegExp("^(block:)?#block([0-9]+)"),page:new RegExp("^(page:)?#landing([0-9]+)"),crmForm:new RegExp("^(form:)?#crmFormPopup([0-9]+)"),crmPhone:new RegExp("^(tel:)?#crmPhone([0-9]+)"),diskFile:new RegExp("^(file:)?#diskFile([0-9]+)"),user:new RegExp("^(user:)?#user([0-9]+)"),system:new RegExp("^#system_[a-z_-]+"),pageOld:new RegExp("^#landing([0-9]+)")};this.typePostfix={skype:"?chat"};this.typeHrefs={page:r.TYPE_HREF_PAGE,block:r.TYPE_HREF_BLOCK,form:r.TYPE_HREF_CRM_FORM,product:r.TYPE_HREF_PRODUCT,file:r.TYPE_HREF_FILE,start:r.TYPE_HREF_START,user:r.TYPE_HREF_USER};i.Dom.addClass(this.layout,"landing-ui-field-link-url");this.requestOptions=e.options||{};this.disableBlocks=i.Type.isBoolean(e.disableBlocks)?e.disableBlocks:false;this.disallowType=i.Type.isBoolean(e.disallowType)?e.disallowType:false;this.iblocks=i.Type.isArray(e.iblocks)?e.iblocks:null;this.allowedTypes=i.Type.isArray(e.allowedTypes)?e.allowedTypes:[r.TYPE_BLOCK,r.TYPE_PAGE];if(this.allowedTypes.length===1){this.constantType=this.allowedTypes[0];this.constantTypeData=e.typeData}this.allowedCatalogEntityTypes=i.Type.isArray(e.allowedCatalogEntityTypes)?e.allowedCatalogEntityTypes:null;this.onInitHandler=i.Type.isFunction(e.onInit)?e.onInit:function(){};this.onNewPageHandler=i.Type.isFunction(e.onNewPage)?e.onNewPage:function(){};this.enableAreas=e.enableAreas;this.customPlaceholder=e.customPlaceholder;this.detailPageMode=e.detailPageMode===true;this.sourceField=e.sourceField;this.currentPageOnly=e.currentPageOnly;this.panelTitle=e.panelTitle;this.onListShow=this.onListShow.bind(this,this.requestOptions);this.onTypeChange=this.onTypeChange.bind(this);this.onListItemClick=this.onListItemClick.bind(this);this.popup=null;this.dynamic=null;this.value=null;this.hrefTypeSwithcer=this.createTypeSwitcher();this.hrefTypeSwithcerValue=this.getHrefStringType();this.grid=this.createGridLayout();this.gridLeftCell=this.grid.querySelector('[class*="left"]');this.gridCenterCell=this.grid.querySelector('[class*="center"]');this.gridRightCell=this.grid.querySelector('[class*="right"]');i.Dom.remove(this.hrefTypeSwithcer.header);i.Dom.append(this.hrefTypeSwithcer.layout,this.gridLeftCell);if(this.getHrefStringType()===r.TYPE_HREF_START){this.gridCenterCell.hidden=true;this.gridRightCell.hidden=true}i.Dom.append(this.input,this.gridCenterCell);i.Dom.append(this.grid,this.layout);if(e.settingMode){i.Dom.addClass(this.gridCenterCell,"setting-mode")}if(!i.Type.isUndefined(this.constantType)){this.rightData=this.getRightData();if(this.rightData.button){const e=this.createCenterCellButton(this.rightData.button);i.Dom.append(e.layout,this.gridCenterCell)}this.contentEditable=false}this.hrefTypeSwithcer.subscribe("onChange",(()=>{this.rightData=this.getRightData();this.input.hidden=this.rightData.hideInput===true;this.gridCenterCell.hidden=false;this.gridRightCell.hidden=false;let e;if(this.rightData.button){e=this.createCenterCellButton(this.rightData.button)}this.emit("buildCenter",{button:e});this.emit("selectAction",{hrefStringType:this.getHrefStringType(),right:this.rightData});if(this.hrefTypeSwithcer.getValue()===r.DELETE_TYPE_HREF){this.deleteTypeHref()}if(this.hrefTypeSwithcerValue!==this.hrefTypeSwithcer.getValue()){this.input.innerHTML="";this.setValue("");this.hrefTypeSwithcerValue=this.hrefTypeSwithcer.getValue()}const t=this.getTypeData(this.hrefTypeSwithcer.getValue());this.setEditPrevented(false);this.contentEditable=t.contentEditable}));const t=this.getHrefStringType();this.setHrefPlaceholderByType(t);this.setHrefTypeSwitcherValue(t);this.removeHrefTypeFromHrefString();this.makeDisplayedHrefValue();if(!i.Type.isUndefined(this.constantType)){if(this.content===""){this.input.innerText="";i.Dom.addClass(this.input,"landing-ui-field-input-empty")}}if(this.disallowType){i.Dom.addClass(this.gridLeftCell,"grid-dissallow")}}setIblocks(e){this.iblocks=i.Type.isArray(e)?e:null}createCenterCellButton(e){let t;if(e.hasOwnProperty("action")){t=this.onListShow.bind(this,e.action)}else{t=e.onclick}const i=`landing-ui-button-grid-center-cell ${e.className||""}`;return new BX.Landing.UI.Button.BaseButton("center_cell_button",{className:i,text:e.text,onClick:t})}makeDisplayedHrefValue(){const e=this.getValue();let t=this.getPlaceholderType();if(!i.Type.isUndefined(this.constantType)){t=this.constantType}let n;switch(t){case r.TYPE_BLOCK:n=this.getBlockData(e);break;case r.TYPE_PAGE:case r.TYPE_HREF_PAGE:n=this.getPageData(e);break;case r.TYPE_CRM_FORM:n=this.getCrmFormData(e);break;case r.TYPE_CRM_PHONE:n=this.getCrmPhoneData(e);break;case r.TYPE_CATALOG_ELEMENT:n=this.getCatalogElementData(e);break;case r.TYPE_CATALOG_SECTION:n=this.getCatalogSectionData(e);break;case r.TYPE_DISK_FILE:n=this.getDiskFileData(e);break;case r.TYPE_USER:n=this.getUserData(e);break;case r.TYPE_SYSTEM:n=this.getSystemPage(e);break;case r.TYPE_CATALOG:n=this.getCatalog(e);break}if(n){n.then(BX.Landing.Utils.proxy(this.createPlaceholder,this)).then(function(e){this.setValue(e,true);if(!this.inited){this.inited=true;this.onInitHandler()}return e}.bind(this)).catch((function(){}))}}getPlaceholderData(e){e=e||this.getValue();const t=this.getPlaceholderType(e);let i=Promise.resolve({});switch(t){case r.TYPE_BLOCK:i=this.getBlockData(e);break;case r.TYPE_PAGE:i=this.getPageData(e);break;case r.TYPE_CATALOG_ELEMENT:i=this.getCatalogElementData(e);break;case r.TYPE_CATALOG_SECTION:i=this.getCatalogSectionData(e);break;case r.TYPE_DISK_FILE:i=this.getDiskFileData(e);break;case r.TYPE_USER:i=this.getUserData(e);break;case r.TYPE_SYSTEM:i=this.getSystemPage(e);break}return i}removeHrefTypeFromHrefString(){const e=this.getValue().replace(new RegExp(this.getHrefStringType(),"g"),"");this.setValue(e,true)}setHrefTypeSwitcherValue(e){if(e===r.TYPE_HREF_START){this.gridCenterCell.hidden=true;this.gridRightCell.hidden=true;this.emit("deleteAction")}else{this.gridCenterCell.hidden=false;this.gridRightCell.hidden=false}this.hrefTypeSwithcer.setValue(e)}getSelectedHrefType(){return this.hrefTypeSwithcer.getValue()}getRightData(){let e=this.hrefTypeSwithcer.getValue();if(!i.Type.isUndefined(this.constantType)){e=this.constantType}const t=this.getTypeData(e);const n=this.getRightTitle(t);const s=this.getRightItems(t);const a=this.getRightButton(t);const l=this.getRightHideInput(t);const r="";return{title:n,items:s,hideInput:l,button:a,idPopup:r}}getRightTitle(e){return e.title}getRightItems(e){return e.items}getRightHideInput(e){return e.hideInput}getRightButton(e){return e.button}getTypeData(e){if(!i.Type.isUndefined(this.constantTypeData)){return this.constantTypeData}const t={};const n="fa fa-chevron-right";switch(e){case r.TYPE_HREF_PAGE:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_PAGE");t.items={_self:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_SELF"),_blank:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_BLANK"),_popup:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_POPUP")};t.button={className:n,text:"",action:r.TYPE_PAGE};t.hideInput=false;t.contentEditable=false;break;case r.TYPE_HREF_BLOCK:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_BLOCK");t.items={_self:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_SELF"),_blank:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_BLANK"),_popup:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_POPUP")};t.button={className:n,text:"",action:r.TYPE_BLOCK};t.hideInput=false;t.contentEditable=false;break;case r.TYPE_HREF_CRM_FORM:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_CRM_FORM");t.button={className:n,text:"",action:r.TYPE_CRM_FORM};t.hideInput=false;t.contentEditable=false;break;case r.TYPE_HREF_PRODUCT:case r.TYPE_CATALOG:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_PRODUCT");t.button={className:n,text:"",action:r.TYPE_CATALOG_SECTION};t.hideInput=false;t.contentEditable=false;break;case r.TYPE_HREF_TEL:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_TEL");t.items={_blank:""};t.button={className:n,text:"",action:r.TYPE_CRM_PHONE};t.contentEditable=true;t.hideInput=false;t.needValidate="phone";break;case r.TYPE_HREF_SMS:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_SMS");t.hideInput=false;t.needValidate="phone";t.contentEditable=true;break;case r.TYPE_HREF_SKYPE:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_SKYPE");t.hideInput=false;t.needValidate="skype";t.contentEditable=true;break;case r.TYPE_HREF_MAILTO:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_MAILTO");t.items={_blank:""};t.hideInput=false;t.needValidate="mail";t.contentEditable=true;break;case r.TYPE_HREF_LINK:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_LINK");t.items={_self:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_SELF"),_blank:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_BLANK"),_popup:BX.Landing.Loc.getMessage("FIELD_LINK_TARGET_POPUP")};t.hideInput=false;t.contentEditable=true;break;case r.TYPE_HREF_FILE:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_FILE");t.items={_blank:""};t.button={className:n,text:"",onclick:this.onDiskFileShow.bind(this)};t.hideInput=false;t.contentEditable=false;break;case r.TYPE_HREF_USER:t.title=BX.Landing.Loc.getMessage("LANDING_LINK_URL_TITLE_USER");t.button={className:n,text:"",onclick:this.onUserListShow.bind(this)};t.hideInput=false;t.contentEditable=false;break}return t}getHrefStringType(){const e=this.getValueText();let t=r.TYPE_HREF_START;if(!i.Type.isUndefined(this.constantType)){return this.constantType}const n=this.matchHrefStringType(e);if(n!==null){return n}if(e==="#"){return t}const s=[r.TYPE_HREF_START,r.TYPE_HREF_PAGE,r.TYPE_HREF_BLOCK,r.TYPE_HREF_CRM_FORM,r.TYPE_HREF_PRODUCT,r.TYPE_HREF_TEL,r.TYPE_HREF_SMS,r.TYPE_HREF_MAILTO,r.TYPE_HREF_SKYPE,r.TYPE_HREF_FILE,r.TYPE_HREF_USER];const a=s.some((function(t){return e.includes(t)}));if(e!==""&&e!=="#"&&!a){return r.TYPE_HREF_LINK}const l=BX.Landing.Utils.join(e.split(":")[0],":");if(e.length!==l.length){switch(l){case r.TYPE_HREF_PAGE:t=r.TYPE_HREF_PAGE;break;case r.TYPE_HREF_BLOCK:t=r.TYPE_HREF_BLOCK;break;case r.TYPE_HREF_CRM_FORM:t=r.TYPE_HREF_CRM_FORM;break;case r.TYPE_HREF_PRODUCT:t=r.TYPE_HREF_PRODUCT;break;case r.TYPE_HREF_TEL:t=r.TYPE_HREF_TEL;break;case r.TYPE_HREF_SMS:t=r.TYPE_HREF_SMS;break;case r.TYPE_HREF_SKYPE:t=r.TYPE_HREF_SKYPE;break;case r.TYPE_HREF_MAILTO:t=r.TYPE_HREF_MAILTO;break;case r.TYPE_HREF_LINK:t=r.TYPE_HREF_LINK;break;case r.TYPE_HREF_FILE:t=r.TYPE_HREF_FILE;break;case r.TYPE_HREF_USER:t=r.TYPE_HREF_USER;break}}return t}matchHrefStringType(e){if(this.matchers.catalogElement.test(e)){return r.TYPE_HREF_PRODUCT}if(this.matchers.catalogSection.test(e)){return r.TYPE_HREF_PRODUCT}if(this.matchers.block.test(e)){return r.TYPE_HREF_BLOCK}if(this.matchers.pageOld.test(e)){return r.TYPE_HREF_PAGE}if(this.matchers.crmForm.test(e)){return r.TYPE_HREF_CRM_FORM}if(this.matchers.crmPhone.test(e)){return r.TYPE_HREF_TEL}if(this.matchers.diskFile.test(e)){return r.TYPE_HREF_FILE}return null}setHrefPlaceholderByType(e){let t=this.placeholder;switch(e){case r.TYPE_HREF_PAGE:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_BUTTON_PAGE");break;case r.TYPE_HREF_BLOCK:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_BUTTON_BLOCK");break;case r.TYPE_HREF_CRM_FORM:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_BUTTON_CRM");break;case r.TYPE_HREF_LINK:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_PLACEHOLDER_URL");break;case r.TYPE_HREF_TEL:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_PLACEHOLDER_PHONE");break;case r.TYPE_HREF_SKYPE:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_PLACEHOLDER_SKYPE");break;case r.TYPE_HREF_SMS:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_PLACEHOLDER_PHONE");break;case r.TYPE_HREF_MAILTO:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_PLACEHOLDER_EMAIL");break;case r.TYPE_HREF_FILE:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_BUTTON_FILE");break;case r.TYPE_HREF_USER:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_BUTTON_USER");break;case r.TYPE_HREF_PRODUCT:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_BUTTON_PRODUCT");break;case r.TYPE_CATALOG:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_BUTTON_CATALOG");break;case r.TYPE_PAGE:t=BX.Landing.Loc.getMessage("LANDING_LINK_URL_BUTTON_PAGE_SHORT");break}i.Dom.attr(this.input,"data-placeholder",t)}getPlaceholderType(e){e=e||this.getValue();if(this.matchers.block.test(e)){return r.TYPE_BLOCK}if(this.matchers.page.test(e)){return r.TYPE_PAGE}if(this.matchers.crmForm.test(e)){return r.TYPE_CRM_FORM}if(this.matchers.crmPhone.test(e)){return r.TYPE_CRM_PHONE}if(this.matchers.catalogElement.test(e)){return r.TYPE_CATALOG_ELEMENT}if(this.matchers.catalogSection.test(e)){return r.TYPE_CATALOG_SECTION}if(this.matchers.diskFile.test(e)){return r.TYPE_DISK_FILE}if(this.matchers.user.test(e)){return r.TYPE_USER}if(this.matchers.system.test(e)){return r.TYPE_SYSTEM}return r.TYPE_HREF_LINK}containsPlaceholder(){return this.input.innerHTML.indexOf("span")!==-1}createGridLayout(){return i.Tag.render(a||(a=s`
			<div class=\"landing-ui-field-link-url-grid --landing-ui-field-link-url__scope\">
				<div class=\"landing-ui-field-link-url-grid-left\"></div>
					<div class=\"landing-ui-field-link-url-grid-center\"></div>
				<div class=\"landing-ui-field-link-url-grid-right\"></div>
			</div>
			`))}onSelectHrefButtonClick(){this.popupActions.show()}createTypeSwitcher(){const e=BX.Landing.Env.getInstance().getType();const t=[{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_SELECT"),value:r.TYPE_HREF_START,hidden:true},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_PAGE"),value:r.TYPE_HREF_PAGE,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--b24"},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_BLOCK"),value:r.TYPE_HREF_BLOCK,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--b24"},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_CRM"),value:r.TYPE_HREF_CRM_FORM,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--crm"},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_PRODUCT"),value:r.TYPE_HREF_PRODUCT,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--product",type:"STORE"},{delimiter:true},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_PHONE"),value:r.TYPE_HREF_TEL,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--phone"},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_SMS"),value:r.TYPE_HREF_SMS,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--sms"},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_EMAIL"),value:r.TYPE_HREF_MAILTO,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--mailto"},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_SKYPE"),value:r.TYPE_HREF_SKYPE,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--skype"},{delimiter:true},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_LINK"),value:r.TYPE_HREF_LINK,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--link"},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_FILE_MSGVER_1"),value:r.TYPE_HREF_FILE,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--file",type:["KNOWLEDGE","GROUP"]},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_USER"),value:r.TYPE_HREF_USER,className:"landing-ui-field-link-url-select-action-item fas landing-ui-field-link-url-icon--user",type:"KNOWLEDGE"},{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_DELETE_ACTION"),value:r.DELETE_TYPE_HREF,className:"landing-ui-field-link-url-delete-action-item fas"}];let n=[];t.forEach((function(t){if(!t.hasOwnProperty("type")||t.type===e||i.Type.isArray(t.type)&&t.type.includes(e)){n.push(t)}}));if(!i.Type.isUndefined(this.constantType)){if(this.constantType===r.TYPE_CATALOG){n=[{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_SELECT_CATALOG"),value:this.constantType}]}if(this.constantType===r.TYPE_PAGE){n=[{name:BX.Landing.Loc.getMessage("LANDING_LINK_URL_ACTION_SELECT_PAGE"),value:this.constantType}]}}return new BX.Landing.UI.Field.Dropdown({items:n,onValueChange:this.onTypeChange,maxHeight:1e3,className:"landing-ui-field-link-url-dropdown-href-type",classForTextNode:"landing-ui-field-input-text"})}onTypeChange(e){const t=e.getValue();this.setHrefPlaceholderByType(t)}getBlockData(e){const t=e.match(/\d+/)[0];return BX.Landing.Backend.getInstance().getBlock({blockId:t}).then((function(e){return e.type="block",e}))}getPageData(e){const t=e.match(/\d+/);if(t!==null){const e=t[0];return BX.Landing.Backend.getInstance().getLanding({landingId:e}).then(function(t){if(!t){if(BX.Text.toNumber(e)===0){this.onNewPageHandler();return{type:"landing",id:0,name:BX.Landing.Loc.getMessage("LANDING_LINK_PLACEHOLDER_NEW_PAGE"),siteId:BX.Landing.Main.getInstance().options.site_id}}else{return null}}return{type:"landing",id:t.ID,name:t.TITLE,siteId:t.SITE_ID}}.bind(this))}}getCrmFormData(e){const t=e.match(/\d+/)[0];return BX.Landing.Backend.getInstance().action("Form::getList").then(function(e){const i=e.find((function(e){return String(e.ID)===String(t)}));if(i){return{type:"crmFormPopup",id:i.ID,name:i.NAME}}return null}.bind(this))}getCrmPhoneData(e){return new Promise(function(t){const i=e.replace("tel:","").replace("#crmPhone","");const n=BX.Landing.Env.getInstance().getOptions().references.find((function(e){return String(e.value)===String(i)}));if(n){t({type:"crmPhone",id:n.value,name:n.text})}else{t(null)}}.bind(this))}getSystemPage(e){return this.cache.remember(e,function(){const e=this.content.replace("#system_","");const t=BX.Landing.Main.getInstance().options.syspages;if(e in t){return Promise.resolve({type:"system",id:"_"+e,name:t[e].name})}return Promise.reject()}.bind(this))}getCatalogElementData(e){return this.cache.remember(e,function(){let t=e.match(this.matchers.catalogElement)[2];if(!i.Type.isString(t)){t=e.match(this.matchers.catalogElement)[1]}const n={elementId:t};return BX.Landing.Backend.getInstance().action("Utils::getCatalogElement",n)}.bind(this))}getCatalogSectionData(e){return this.cache.remember(e,function(){let t=e.match(this.matchers.catalogSection)[2];if(!i.Type.isString(t)){t=element.match(this.matchers.catalogSection)[1]}const n={sectionId:t};return BX.Landing.Backend.getInstance().action("Utils::getCatalogSection",n)}.bind(this))}getCatalog(e){if(e==="={$sectionId}"||e==="selectActions:"){return null}return this.cache.remember(e,function(){let t;let i;let n;t=e.match(this.matchers.catalog);if(t===null){t=e.match(this.matchers.element);if(t!==null){n="Element"}}else{n="Section"}if(t){i=t[1]}let s=null;if(n==="Section"){s={sectionId:i}}if(n==="Element"){s={elementId:i}}if(s===null){return null}const a="Utils::getCatalog"+n;return BX.Landing.Backend.getInstance().action(a,s)}.bind(this))}getDiskFileData(e){return this.cache.remember(e,function(){const t=e.replace("file:","").replace("#diskFile","");return BX.Landing.Backend.getInstance().action("Block::getFileDisk",{fileId:t}).then(function(e){if(e){return{type:r.TYPE_DISK_FILE,id:e.ID,name:e.NAME}}return null}.bind(this))}.bind(this))}getUserData(e){const t=e.replace("user:","").replace("#user","");return new Promise(function(e){BX.ajax({url:"/bitrix/services/main/ajax.php?action=landing.api.user.getUserNameById",method:"POST",dataType:"json",data:{userId:t},onsuccess:function(i){const n={type:r.TYPE_USER,id:t,name:i.data};e(n)}})}.bind(this))}deleteTypeHref(){this.gridCenterCell.hidden=true;this.gridRightCell.hidden=true;this.setHrefTypeSwitcherValue(r.TYPE_HREF_START);this.setHrefPlaceholderByType(r.TYPE_HREF_START);this.emit("deleteAction")}onSelectButtonClick(){if(this.allowedTypes.length===1){this.onListShow(this.allowedTypes[0])}}onListShow(e,t){if(this.popup){this.popup.close()}if(t===r.TYPE_CATALOG_SECTION||t===r.TYPE_CATALOG){let e=this.iblocks;if(!i.Type.isArray(e)){e=BX.Landing.Main.getInstance().options.iblocks}void BX.Landing.UI.Panel.Catalog.getInstance().show(e,this.allowedCatalogEntityTypes).then(this.onListItemClick);return}e.enableAreas=this.enableAreas;e.dynamicMode=true;e.currentPageOnly=this.currentPageOnly;e.panelTitle=this.panelTitle;if(this.detailPageMode){e.source=this.sourceField.getValue().source;void BX.Landing.UI.Panel.DetailPage.getInstance().show(e).then(this.onListItemClick)}else{const i=BX.Landing.UI.Panel.URLList.getInstance();void i.show(t,e).then(this.onListItemClick)}}onDiskFileShow(){if(this.popup){this.popup.close()}parent.BX.Landing.Connector.Disk.openDialog({onSelect:e=>{this.getDiskFileData("#diskFile"+e).then(function(e){this.setValue(this.createPlaceholder(e),true)}.bind(this));this.setHrefTypeSwitcherValue(r.TYPE_HREF_FILE)}})}onUserListShow(){this.dialog=new n.Dialog({targetNode:this.input,enableSearch:true,context:"MY_MODULE_CONTEXT",entities:[{id:r.TYPE_USER},{id:"department"}],events:{"Item:onSelect":this.onSelectUser.bind(this)},multiple:false,popupOptions:{targetContainer:parent.document.body}});this.dialog.show()}onSelectUser(){const e=this.dialog.getSelectedItems()[0];const t={name:e.title.text,type:r.TYPE_USER,id:e.id};this.setValue(this.createPlaceholder(t));BX.Landing.Utils.fireEvent(this.layout,"input");this.setHrefTypeSwitcherValue(t.type+":")}isEditPrevented(){if(!i.Type.isBoolean(this.editPrevented)){this.editPrevented=this.containsPlaceholder()}return this.editPrevented}setEditPrevented(e){this.editPrevented=e}enableEdit(){if(!this.isEditPrevented()){BX.Landing.UI.Field.Text.prototype.enableEdit.apply(this)}}createPlaceholder(e){i.Dom.addClass(this.gridCenterCell,"--not-empty");if(i.Type.isString(e)){return e}const t=i.Tag.render(l||(l=s`
			<span class=\"landing-ui-field-url-placeholder\">
				<span class=\"landing-ui-field-url-placeholder-preview\"></span>
				<span class=\"landing-ui-field-url-placeholder-text\">
					${0}
				</span>
				<span class=\"landing-ui-field-url-placeholder-delete\"></span>
			</span>
		`),BX.Landing.Utils.encodeDataValue(e.name));const n=t.querySelector('[class*="delete"]');i.Event.bind(n,"click",this.onPlaceholderRemoveClick.bind(this));if(e.type===r.TYPE_CATALOG){e.chain.push(e.name);const n=BX.Landing.Utils.join(e.name,"\n",e.chain.join(" / "));i.Dom.attr(t,{"data-dynamic":{type:BX.Landing.Utils.join(r.TYPE_CATALOG,BX.Landing.Utils.capitalize(e.subType)),value:e.id},"data-placeholder":BX.Landing.Utils.join("#",e.type,BX.Landing.Utils.capitalize(e.subType),e.id),"data-url":BX.Landing.Utils.join("#",e.type,BX.Landing.Utils.capitalize(e.subType),e.id)});t.setAttribute("title",n);return t}BX.Landing.Utils.attr(t,{"data-placeholder":BX.Landing.Utils.join("#",e.type,e.id),"data-url":BX.Landing.Utils.join("#",e.type,e.id)});t.setAttribute("title",e.name);return t}onPlaceholderRemoveClick(e){i.Dom.removeClass(this.gridCenterCell,"--not-empty");this.setEditPrevented(false);this.enableEdit();i.Dom.remove(e.target.parentNode);this.setValue("");BX.Landing.Utils.fireEvent(this.layout,"input");this.onInputHandler(this.input.innerText)}onListItemClick(e){let t=Promise.resolve(e);if(e.type==="block"){t=this.getBlockData("#block"+e.id)}t.then(function(e){this.setValue(this.createPlaceholder(e));BX.Landing.Utils.fireEvent(this.layout,"input");this.setHrefTypeSwitcherValue(e.type+":")}.bind(this))}getNewLabel(){if(!this.newLabel){this.newLabel=i.Dom.create({tag:"div",props:{className:"landing-ui-field-link-new-label"},text:BX.Landing.Loc.getMessage("LANDING_LINK_NEW_PAGE_LABEL")})}return this.newLabel}showNewLabel(){BX.Dom.style(this.gridCenterCell,{position:"relative",overflow:"visible"});BX.Dom.append(this.getNewLabel(),this.gridCenterCell)}hideNewLabel(){BX.Dom.style(this.gridCenterCell,"overflow",null);BX.Dom.remove(this.getNewLabel())}setValue(e,t){if(i.Type.isObject(e)&&!i.Type.isNil(e)){this.disableEdit();this.setEditPrevented(true);this.input.innerHTML="";i.Dom.append(e,this.input);const n=e["dataset"];this.value=n.placeholder;this.dynamic=n.dynamic;if(this.value==="#landing0"){this.showNewLabel()}else{this.hideNewLabel()}if(!t){this.onInputHandler(this.input.innerText)}}else if(!i.Type.isNil(e)){this.setEditPrevented(false);this.input.innerText=this.getInputInnerText(e);this.value=null;this.dynamic=null;this.hideNewLabel()}if(!t){if(i.Type.isString(this.value)){this.getPlaceholderData(this.value).then(function(e){this.onValueChangeHandler(e)}.bind(this)).catch((function(){}));return}this.onValueChangeHandler(null)}}getDynamic(){return this.dynamic}getValue(){let e=this.value?this.value:this.input.innerText;const t=this.getSelectedHrefType();this.validateValue(e);this.prepareInputField(this.hrefTypeSwithcer.getValue(),e);if(e===""){if(t==="catalog"){return""}return r.TYPE_HREF_START}if(t===r.TYPE_HREF_SKYPE&&!e.includes(this.typePostfix.skype)){e=e+this.typePostfix.skype}if(e.startsWith(t)){return e}if(!i.Type.isUndefined(this.constantType)){if(this.constantType===r.TYPE_CATALOG){if(this.matchers.catalogElement.test(e)||this.matchers.catalogSection.test(e)||this.matchers.catalog.test(e)||this.matchers.element.test(e)){return e}return""}if(this.constantType===r.TYPE_PAGE){return r.TYPE_HREF_PAGE+e}}return t+e}getValueText(){return this.value?this.value:this.input.innerText}validateValue(e){if(e.indexOf(":")!==-1){e=e.slice(e.indexOf(":")+1)}const t=[];t["phoneExtended"]=/(^[\d+][\d-]{4,14}\d$)|#crmPhone\d+/;t["phone"]=/^[\d+][\d-]{4,14}\d$/;t["mail"]=/^\S+@\S+[.]\S+$/i;t["skype"]=/^[a-z\d-.:]{6,32}$/i;const n=this.hrefTypeSwithcer.getValue();const s=this.getTypeData(n);let a=true;if(s.needValidate){let s;switch(n){case r.TYPE_HREF_TEL:s=t["phoneExtended"];break;case r.TYPE_HREF_SMS:s=t["phone"];break;case r.TYPE_HREF_MAILTO:s=t["mail"];break;case r.TYPE_HREF_SKYPE:s=t["skype"];break}if(s){if(e.length>0){const t=s.test(e);if(t){i.Dom.removeClass(this.gridCenterCell,"--validate-incorrect");i.Dom.addClass(this.gridCenterCell,"--validate-correct")}else{i.Dom.removeClass(this.gridCenterCell,"--validate-correct");i.Dom.addClass(this.gridCenterCell,"--validate-incorrect");a=false}}else{i.Dom.removeClass(this.gridCenterCell,"--validate-correct");i.Dom.removeClass(this.gridCenterCell,"--validate-incorrect")}}}else{i.Dom.removeClass(this.gridCenterCell,"--validate-correct");i.Dom.removeClass(this.gridCenterCell,"--validate-incorrect")}this.emit("readyToSave",{readyToSave:a})}prepareInputField(e,t){const n=[r.TYPE_HREF_PAGE,r.TYPE_HREF_BLOCK,r.TYPE_HREF_CRM_FORM,r.TYPE_HREF_FILE,r.TYPE_HREF_USER,r.TYPE_HREF_PRODUCT,r.TYPE_CATALOG,r.TYPE_PAGE];if(t===""&&n.includes(e)){i.Dom.addClass(this.input,"landing-ui-field-input-empty")}else{i.Dom.removeClass(this.input,"landing-ui-field-input-empty")}}getInputInnerText(e){return this.prepareInputInnerText(e.toString().trim())}prepareInputInnerText(e){if(this.getSelectedHrefType()===r.TYPE_HREF_SKYPE&&e.includes(this.typePostfix.skype)){e=e.replace(this.typePostfix.skype,"")}return e}}r.TYPE_BLOCK="block";r.TYPE_PAGE="landing";r.TYPE_CRM_FORM="crmFormPopup";r.TYPE_CRM_PHONE="crmPhone";r.TYPE_SYSTEM="system";r.TYPE_CATALOG="catalog";r.TYPE_CATALOG_ELEMENT="element";r.TYPE_CATALOG_SECTION="section";r.TYPE_DISK_FILE="diskFile";r.TYPE_USER="user";r.TYPE_HREF_START="selectActions:";r.TYPE_HREF_PAGE="page:";r.TYPE_HREF_BLOCK="block:";r.TYPE_HREF_CRM_FORM="form:";r.TYPE_HREF_PRODUCT="product:";r.TYPE_HREF_TEL="tel:";r.TYPE_HREF_SMS="sms:";r.TYPE_HREF_MAILTO="mailto:";r.TYPE_HREF_SKYPE="skype:";r.TYPE_HREF_LINK="";r.TYPE_HREF_FILE="file:";r.TYPE_HREF_USER="user:";r.DELETE_TYPE_HREF="deleteTypeHref";e.LinkUrl=r})(this.BX.Landing.UI.Field=this.BX.Landing.UI.Field||{},BX.Landing.UI.Field,BX,BX.UI.EntitySelector);
//# sourceMappingURL=linkurl.bundle.map.js